package kczy;
import java.util.*;

import javax.management.RuntimeErrorException;
class User{

    public int cardNumbe;       //卡号
    public int passwword;       //密码
    public int balance;         // 余额
    public String name;
    User   naxt;

}
//这里------------------------------------------------------------------------------------------------------------------------
class Card{
    User head;
    int i;  
    public void mb(){
        User user =new User();
        if(this.head==null){
            this.head=user;
            user.passwword=123;
            this.i++;
            return;
        }
        User cur=this.head;
        while(cur.naxt!=null){
            cur=cur.naxt;
        }
        cur.naxt=user;
        user.passwword=123;
        this.i++;
    }                   //计数器
    public void ganerate(){                     //生成卡
        User user=new User();
        Scanner scanner=new Scanner(System.in);
        User cur=this.head;
        if(this.head==null){
            this.head=user;
            System.out.println("请输入您的姓名");
            user.name=scanner.nextLine();
            user.name=scanner.nextLine();
            System.out.println(i+"您的卡号");
            System.out.println("请输入您的密码");
            user.passwword=scanner.nextInt();
            user.cardNumbe=i;
           
            this.i++;
            return;
        }
        while(cur.naxt!=null){
            cur=cur.naxt;
        }
        cur.naxt=user;
        System.out.println(i+"您的卡号");
        System.out.println("请输入您的密码");
        user.passwword=scanner.nextInt();
        System.out.println("请输入您的姓名");
            user.name=scanner.nextLine();
            user.name=scanner.nextLine();
        user.cardNumbe=i;
        this.i++;
    }
    public void panDuan(int cardNumde,int password){
        User flg=this.head;
        while(cardNumde!=0){
            flg=flg.naxt;
            cardNumde--;
        }
        if(password!=flg.passwword){
            return;
        }
        else{
            serveWindow(flg);
        }
    }
    //------------------------------------------------------------------------------------------------------------------------------
    //可拆分封装成类      -----------------------------------------------------------------------------------------------
    public void denglu(){
        int cardNumde,password;
        Scanner scanner=new Scanner(System.in);
        while(true){
            
                System.out.println("***************************************************");
                System.out.println("****************中国人民天地银行*******************");
                System.out.println("***********感受这被囚禁了千万年的愤怒***************");
                System.out.println("***************************************************");
                System.out.println("***************************************************");
                System.out.println("*****************登录：1***************************");
                System.out.println("*****************注册：2***************************");
                System.out.println("*****************退出：3***************************");
                System.out.println("***************************************************");
                System.out.println("**********热线电话66666666666**********************");
                System.out.println("********************************行长：伊利丹*******");
                System.out.println("***************************************************");

                int j=scanner.nextInt();
                if(j==0){
                    return;
                }
                else if(j==2){
                ganerate();  
                }
                else{
                    int i=0;
                    i++;
                    System.out.println("请输入用户名");
                    cardNumde=scanner.nextInt();
                    System.out.println("请输入密码");
                    password=scanner.nextInt();
                    panDuan(cardNumde, password);
                    if(i==2){
                        throw new RuntimeException("您已经尝试3次，自动退出");
                    }
                    return;
                }
            }
    }
    //-----------------------------------------------------------------------------------------------------------------------------
    //当然这个也可以------------------------------------------------------------------------------------------------------------------
    public void deposit(User user){                                         //存
        Scanner scanner=new Scanner(System.in);
        int money;
        System.out.println("请输入您需要存的数码");
        money=scanner.nextInt();
        if(money>=100&&money%10==0){
            user.balance=user.balance+money;
        }
        System.out.println(user.balance);
    }
    public void withdrawal(User user){                                      //取
        Scanner scanner=new Scanner(System.in);
        int money;
        System.out.println("请输入您需要取的数码");
        money=scanner.nextInt();
        if(money>user.balance){
            System.out.println("没有足够的与额");
        }
        if(money>=100&&money%10==0&&money<user.balance){
            user.balance=user.balance-money;
        }
        System.out.println(user.balance);

    }
    public void modification(User user){
        System.out.println("请输入用户名和密码");
        Scanner scanner=new Scanner(System.in);
        int cardNumde=scanner.nextInt();
        int password=scanner.nextInt();
        User cur;
        cur=this.head;
        while(cardNumde!=0){
            cur=cur.naxt;
            cardNumde--;
        }
        if(cur.passwword==password){
            System.out.println("请输入新的密码");
            cur.passwword=scanner.nextInt();
            denglu();
        }
    }
    public void serveWindow(User user){
        Scanner scanner=new Scanner(System.in);
        while(true){
            System.out.println("*******************************************************");
            System.out.println("************欢迎"+user.name+"光临中国人民天地银行******");
            System.out.println("*******************************************************");
            System.out.println("*******************************************************");
            System.out.println("********存款：1*******************取款：2**************");
            System.out.println("*******************************************************");
            System.out.println("*******************************************************");
            System.out.println("******修改密码：3***************查询余额：4************");
            System.out.println("*******************************************************");
            System.out.println("*******************************************************");
            System.out.println("*************************************退出：0************");
            System.out.println("*******************************************************");
            System.out.println("*******************************************************");
            int i;
            i=scanner.nextInt();
            switch(i){
                case 1:
                deposit(user);
                    break;
                case 2:
                withdrawal(user);
                    break;
                case 3:
                modification(user);
                    break;
                case 4:
                System.out.println(user.balance);
                    break;
                case 0:
                    return ;
            }
            
        }
    }    
}

//到这里--------------------------------------------------------------------------------------------